package com.chixing.day11_exception;

import org.w3c.dom.Node;

public class LinkString {
    private Node first;
    private Node last;
    private  int size;//已有元素个数
    private int modifierCount; //整个该容器结构上发生修改的次数，结构上（添加，删除元素）
                               // 防止快速迭代失败（防止在遍历的时候，有元素删除或添加）

    public void addLast(String element){
        if(first == null) {
            first = new Node(null, element, null);
            last = first;
        }else{
          Node oldLast= last;
          last = new Node(oldLast,element,null);
          oldLast.next = last;

        }
        size++;
        modifierCount++;
    }

    private class Node{
        String value;// 元素值本身
        Node previous;//前一个元素
        Node next;//否一个元素

        private Node(Node previous,String value,Node next){
            this.value = value;
            this.previous = previous;
            this.next = next;

        }
    }
    public void show(){
        Node node = first;
         while (node !=null){
             System.out.println(node.value);
             node = node.next;
         }
    }
}
